﻿CREATE TABLE [dbo].[tblOrderHeader] (
    [OrderID]              INT           IDENTITY (1, 1) NOT NULL,
    [CustomerID]           INT           NOT NULL,
    [OrderDate]            SMALLDATETIME NOT NULL,
    [ProjShipDate]         SMALLDATETIME NOT NULL,
    [OrderTypeCode]        CHAR (1)      NOT NULL,
    [ProductTotal]         MONEY         NOT NULL,
    [Shipping]             MONEY         NULL,
    [Taxes]                MONEY         NOT NULL,
    [OrderTotal]           MONEY         NOT NULL,
    [Location]             VARCHAR (10)  NULL,
    [ImportDate]           DATETIME      NOT NULL,
    [DetailCount]          SMALLINT      NULL,
    [HoldReasonCode]       CHAR (1)      NULL,
    [AccountID]            INT           NULL,
	[BankCheckNumber]	   INT			 NULL,
    [ShipTo_PersonID]      INT           NULL,
    [ShipTo_CompanyName]   NVARCHAR (50) NULL,
    [ShipTo_AddressID]     INT           NOT NULL,
    [AgentID]              INT           NULL,
    [OrderSourceCode]      CHAR(1)       NULL,
	[PrePaid]			   bit			 null,
	[PromotionID]		   int			 null,
    [OrderStatusCode]      CHAR (1)      NULL,
    [CanceledReasonID]     INT           NULL,
	[CanceledDate]		   SMALLDATETIME NULL,
    [PreferredCarrierCode] CHAR (1)      NULL,
    [OwnerID]              INT           NOT NULL,
	[ImportBatchID]		   int			 null,
	[InvoiceDate]		   smalldatetime null,
	[SequenceOrderStepID]  INT			 NULL,
	[SequenceCount]		   INT			 NULL,
	[UserDefined1]         NVARCHAR (50)  NULL,
	[UserDefined2]         NVARCHAR (50)  NULL,
	[UserDefined3]         NVARCHAR (10)  NULL,
	[UserDefined4]         NVARCHAR (10)  NULL,
	[UserDefined5]         INT            NULL,
	[UserDefined6]         INT            NULL,
	[UserDefined7]         SMALLDATETIME  NULL,
	[UserDefined8]         BIT            NULL,
	[UserDefined9]         BIT            NULL
);
GO
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Defines an order.', @level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'primary key.  Uniquely identifies each order.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The customer number of the customer to whom this order belongs.  Links to tblCustomer.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'CustomerID';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The date the order was taken', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderDate';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The date the order is expected to ship', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'ProjShipDate';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The type of order such as Web, Autoship, Customer Service, etc.  See codeOrderType', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderTypeCode';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'QtyOrdered * UnitPrice - Discount', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'ProductTotal';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The shipping cost for the order.  Shipping is allowed to be null to allow for processing to decide when to calculate shipping.', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'Shipping';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Any applicable state sales tax', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'Taxes';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'ProductTotal + Shipping + Taxes', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'OrderTotal';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Call center where this order was taken.  See vdn_MSTCallCenter', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'Location';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The date the record was imported into tblOrderHeader', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'ImportDate';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The number of order detail records', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'DetailCount';
GO;
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'The ID of the Agent who took the order', 
	@level0type = N'SCHEMA', @level0name = N'dbo',
	@level1type = N'TABLE', @level1name = N'tblOrderHeader',
	@level2type = N'COLUMN', @level2name = N'AgentID';

